package com.sumainfor.pc.market.service.impl;

import com.sumainfor.pc.market.dao.OpenApiMapper;
import com.sumainfor.pc.market.feign.Zfeign.ZzuulFeign;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Author Eddy·Chen
 * @Email 835033913@qq.com
 * @Create 2019-04-20 12:54
 */
@Service
@Log4j2
@Transactional(rollbackFor = Exception.class)
public class OpenApiService {

    @Autowired
    private OpenApiMapper apiMapper;

    @Autowired
    private ZzuulFeign zuulFeign;

    /**
     * 获取服务中心数据 通过区的编号查询
     *
     * @param districtID
     * @return
     */
    public List<Map<String, Object>> selectServiceCenterByDistrictId(String districtID) {
        return apiMapper.selectServiceCenterByDistrictId(districtID).stream().map(item -> {
            Map<String, Object> info = zuulFeign.getDeptInfoById(MapUtils.getString(item, "MiId"));
            item.put("name", info.get("name"));
            return item;
        }).collect(Collectors.toList());
    }

}
